package com.ruoyi.web.dorm.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.dorm.entity.ClassEntity;
import com.ruoyi.web.dorm.entity.StudentEntity;
import com.ruoyi.web.dorm.entity.dto.StudentDTO;
import com.ruoyi.web.dorm.entity.vo.ClassStudentVO;
import com.ruoyi.web.dorm.entity.vo.ClassVO;
import com.ruoyi.web.dorm.entity.vo.StudentVO;
import com.ruoyi.web.dorm.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/dorm/class")
public class ClassController extends BaseController {

    @Autowired
    private ClassService classService;


    /**
     * 查询班级信息
     * @param classVO
     * @return
     */
    @GetMapping("/classList")
    public TableDataInfo classList(ClassVO classVO){
        startPage();
        return getDataTable(classService.classList(classVO));
    }


    /**
     * 添加班级信息
     * @param classEntity
     * @return
     */
    @PostMapping("/addClass")
    public AjaxResult addClass(@RequestBody  ClassEntity classEntity){
        return toAjax(classService.addClass(classEntity));
    }


    /**
     * 更新班级信息
     * @param classEntity
     * @return
     */
    @PostMapping("/updateClass")
    public AjaxResult updateClass(@RequestBody ClassEntity classEntity){
        return toAjax(classService.updateClass(classEntity));
    }

    /**
     * 删除班级信息
     * @param id
     * @return
     */
    @DeleteMapping("/delClass")
    public AjaxResult delClass(Long id){
        return toAjax(classService.delClass(id));
    }



    /**
     * 查询班级信息导出信息
     * @param classVO
     * @return
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response,ClassVO classVO){
        List<ClassVO> list = classService.classList(classVO);
        ExcelUtil<ClassVO> util = new ExcelUtil<>(ClassVO.class);
        util.exportExcel(response,list,"班级信息数据");
    }


    /**
     * 查询班级学生信息
     * @param classStudentVO
     * @return
     */
    @GetMapping("/classStudentList")
    public TableDataInfo classStudentList( ClassStudentVO classStudentVO){
        startPage();
        return getDataTable(classService.classStudentList(classStudentVO));
    }




}
